package com.ruoyi.web.controller.erpbase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Phone;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Drivers;
import com.ruoyi.system.service.IDriversService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 司机Controller
 * 
 * @author he
 * @date 2025-08-06
 */
@Api(tags = "司机接口")
@RestController
@RequestMapping("/system/drivers")
public class DriversController extends BaseController
{
    @Autowired
    private IDriversService driversService;

    /**
     * 查询司机列表
     */
    @ApiOperation("查询司机信息")
    @PreAuthorize("@ss.hasPermi('system:drivers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drivers drivers)
    {
        startPage();
        List<Drivers> list = driversService.selectDriversList(drivers);
        return getDataTable(list);
    }

    @ApiOperation("司机下拉框信息")
    @PostMapping("/getDriverInfoList")
    public TableDataInfo getDriverInfoList(@RequestParam(value = "paramName", required = false) String paramName)
    {
        List<Drivers> list = driversService.getDriverInfoList(paramName);
        return getDataTable(list);
    }

    /**
     * 导出司机列表
     */
    @ApiOperation("导出司机信息")
    @PreAuthorize("@ss.hasPermi('system:drivers:export')")
    @Log(title = "司机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Drivers drivers)
    {
        List<Drivers> list = driversService.selectDriversList(drivers);
        ExcelUtil<Drivers> util = new ExcelUtil<Drivers>(Drivers.class);
        util.exportExcel(response, list, "司机数据");
    }

    /**
     * 获取司机详细信息
     */
    @ApiOperation("司机详细信息")
    @PreAuthorize("@ss.hasPermi('system:drivers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(driversService.selectDriversById(id));
    }

    /**
     * 新增司机
     */
    @ApiOperation("新增司机信息")
    @PreAuthorize("@ss.hasPermi('system:drivers:add')")
    @Log(title = "司机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drivers drivers)
    {
        drivers.setCreateUserId(SecurityUtils.getUserId());
        drivers.setCreateUserName(SecurityUtils.getUsername());
        drivers.setCreateTime(DateUtils.getNowDate());
        return toAjax(driversService.insertDrivers(drivers));
    }

    /**
     * 修改司机
     */
    @ApiOperation("修改司机信息")
    @PreAuthorize("@ss.hasPermi('system:drivers:edit')")
    @Log(title = "司机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drivers drivers)
    {
        drivers.setUpdateUserId(SecurityUtils.getUserId());
        drivers.setUpdateUserName(SecurityUtils.getUsername());
        drivers.setUpdateTime(DateUtils.getNowDate());
        return toAjax(driversService.updateDrivers(drivers));
    }

    /**
     * 删除司机
     */
    @ApiOperation("删除司机信息")
    @PreAuthorize("@ss.hasPermi('system:drivers:remove')")
    @Log(title = "司机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driversService.deleteDriversByIds(ids));
    }



    /**
     * 修改司机
     */
//    @PreAuthorize("@ss.hasPermi('system:drivers:edit')")
    @Log(title = "司机手机端", businessType = BusinessType.UPDATE)
    @PutMapping("updateDriverPhone")
    public AjaxResult updateDriverPhone(@RequestBody Phone phone)
    {

        return toAjax(driversService.updateDriverPhone(phone));
    }


//    @PreAuthorize("@ss.hasPermi('system:drivers:query')")
//    @GetMapping(value = "driverInfoPhone")
//    public AjaxResult driverInfoPhone()
//    {
//        return success(driversService.driverInfoPhone(appointment.getFwid()));
//    }

}
